package com.example.demo99.Controller;

import com.example.demo99.Entity.VO.ProductSalesStatsVO;
import com.example.demo99.Entity.VO.SalesTrendVO;
import com.example.demo99.Service.SalesStatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController

@RequestMapping("/api/sales")
public class SalesStatisticsController {

    @Autowired
    private SalesStatisticsService salesStatisticsService;

    // 获取某段时间内销售最多的产品
    @GetMapping("/top-product")
    public ProductSalesStatsVO getTopProduct(@RequestParam String startDate, @RequestParam String endDate) {
        return salesStatisticsService.getTopSellingProduct(startDate, endDate);
    }

    // 获取每个产品总销售数量与金额
    @GetMapping("/summary")
    public List<ProductSalesStatsVO> getSalesSummary(@RequestParam String startDate, @RequestParam String endDate) {
        return salesStatisticsService.getProductSalesStats(startDate, endDate);
    }

    // 获取销售趋势（按月）
    @GetMapping("/trend")
    public List<SalesTrendVO> getSalesTrend(@RequestParam String startDate, @RequestParam String endDate) {
        return salesStatisticsService.getSalesTrendByMonth(startDate, endDate);
    }
}